﻿<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
  <xsl:output version="4.0" method="html" indent="no"  omit-xml-declaration="yes" encoding="UTF-8" doctype-public="-//W3C//DTD HTML 4.01 Transitional//EN" doctype-system="http://www.w3.org/TR/html4/loose.dtd"/>
  <xsl:template match="//form">
    <script type="text/javascript">
      function submitform()
      {
      $.post("/Home/Store", $("#clinicalform").serialize(), function(data) {
      // This is our documentID
      $("#state #selectedDocumentID").val(data);
      // Now pop off and get the updated document list!
      //CategoryClickSync($("#categories li.selected"));
      //$("#categories li.selected").click();
      // Now select the document in the list
      SelectDocumentByDocumentID(data);
      alert(data);
      });
      return false;
      }
    </script>
    <div id="form">
      <h1>
        <xsl:value-of select="title"/>
      </h1>
      <form action="/Home/Store" method="post" id="clinicalform">
      <xsl:for-each select="formelement">
        <xsl:variable name="elementname" select="./input/@name"/>
        <xsl:variable name="elementtype" select="./input/@type"/>
        <xsl:variable name="elementvalue" select="./input/."/>
        <xsl:choose>
          <xsl:when test="$elementtype = 'hidden'">
              <input type="hidden" name="{$elementname}" value="{$elementvalue}" />
          </xsl:when>
          <xsl:otherwise>
            <p>
              <label>
                <xsl:value-of select="./label"/>
              </label>
              <xsl:choose>
                <xsl:when test="$elementtype='text'">
                  <input type="text" name="{$elementname}"></input>
                </xsl:when>
                <xsl:when test="$elementtype='multilinetext'">
                  <textarea name="{$elementname}"></textarea>
                </xsl:when>
              </xsl:choose>
            </p>
          </xsl:otherwise>
        </xsl:choose>
        
      </xsl:for-each>
        <button id="btnSubmit" onclick="return submitform();">Store</button>
      </form>
    </div>
  </xsl:template>
</xsl:stylesheet>
